package com.lin.manager.quartz;

import org.quartz.spi.TriggerFiredBundle;
import org.springframework.context.ApplicationContext;
import org.springframework.scheduling.quartz.SpringBeanJobFactory;

/**
 * @作者: 林江
 * @创建时间: 2024/3/25
 * @功能: job实例中,能够自动注册属性
 */
public class CustomJobFactory extends SpringBeanJobFactory {

    ApplicationContext applicationContext;

    @Override
    protected Object createJobInstance(TriggerFiredBundle bundle) throws Exception {
        // spring创建的实列范围是   原型模式.
        Object job = super.createJobInstance(bundle);
        // 自动注入属性
        applicationContext.getAutowireCapableBeanFactory().autowireBean(job);
        return job;
    }

    public void setApplicationContext(ApplicationContext applicationContext) {
        super.setApplicationContext(applicationContext);
        this.applicationContext = applicationContext;
    }
}
